fix(sql): return planner error for malformed typed literals#21454
Merged
jonahgao merged 2 commits intoapache:mainfrom Apr 11, 2026
Merged
fix(sql): return planner error for malformed typed literals#21454jonahgao merged 2 commits intoapache:mainfrom
jonahgao merged 2 commits intoapache:mainfrom
Conversation
niebayes
approved these changes
Apr 8, 2026
jonahgao
reviewed
Apr 10, 2026
datafusion/sql/src/expr/mod.rs
Outdated
| self.convert_data_type_to_field(&data_type)?, | ||
| ))), | ||
| }) => { | ||
| let raw_value = value.to_string(); |
Member
There was a problem hiding this comment.
raw_value is only used in the error branch,introducing a redundant string allocation on the happy path.
How about excluding it from the error message?
let value = value.into_string().ok_or_else(|| {
plan_datafusion_err!("Typed literal requires a string payload")
})?;
Contributor
Author
There was a problem hiding this comment.
Adjusted this to avoid the happy-path allocation in f416e71.
Guard SQL typed-literal planning against non-string payloads instead of panicking on unwrap. Add a regression test for the invalid TIME literal path reported in apache#21431. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
799635a to
f416e71
Compare
jonahgao
approved these changes
Apr 11, 2026
Member
jonahgao
left a comment
There was a problem hiding this comment.
LGTM, thanks @officialasishkumar @niebayes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
TIMEtyped literal causes planner panic #21431.Rationale for this change
Planning a malformed typed literal such as
time 17542368000000000currently panics indatafusion-sqlbecause the planner assumes everyTypedStringpayload is string-backed and callsinto_string().unwrap().Invalid SQL should surface as a normal planner error rather than aborting the planning path.
What changes are included in this PR?
unwrap()in theSQLExpr::TypedStringplanning path with explicit validation.TIMEtyped literal reported in the issue.Are these changes tested?
cargo test -p datafusion-sqlAre there any user-facing changes?
Users now receive a planner error for malformed typed literals instead of a panic.